﻿using JustMetClient.Modules.LoginModule;
using Azylee.Core.WindowsUtils.APIUtils;
using JustMetClient.Commons;
using JustMetClient.Modules.SocketModule;
using JustMetClient.Modules.WebModule;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using JustMetClient.Socket;
using Azylee.WinformSkin.FormUI.CustomTitle;
using Azylee.Core.DataUtils.DateTimeUtils;
using Azylee.Core.WindowsUtils.InfoUtils;
using Azylee.Core.DataUtils.UnitConvertUtils;
using JustMetClient.Socket.Models;
using JustMetClient.Views.InfoViews;
using Azylee.Core.IOUtils.DirUtils;
using Azylee.YeahWeb.BaiDuWebAPI.IPLocationAPI;
using Azylee.Core.IOUtils.TxtUtils;
using System.Security.Cryptography;
using BigClipboard.Models;
using BigClipboard.Modules.ClipboardDataModule;
using System.Diagnostics;
using System.Runtime.InteropServices;
using Azylee.Core.DataUtils.CollectionUtils;
using System.Drawing.Drawing2D;
using System.IO;

namespace JustMetClient
{
    public partial class MainForm : SingleTitleForm
    {
        public MainForm()
        {
            InitializeComponent();
            Init();
            InitView();
            NetWorkInit();
            HideTabControlHead();
        }

        #region View（初始化）

        /// <summary>
        /// 初始化View
        /// </summary>
        private void InitView()
        {
            LBVersion.Text = "版本：" + R.Version.ToString();
            menuPart1.MenuClick += FunctionMenu_Click;
            this.TPMain.BorderStyle = BorderStyle.None;
            LBIPLocation.Height = 30;
            TCFunction.Dock = DockStyle.Fill;

        }
        private void MainForm_Load(object sender, EventArgs e)
        {
        }

        /// <summary>
        /// 更新连接状态
        /// </summary>
        public void UpdateConnStatus(bool conn)
        {
            BeginInvoke(new Action(() =>
            {
                string text = conn ? "已连接" : "连接失败";
                LBConnectStatus.Text = text;
                R.Account = R.NetInfo.Mac;
            }));
        }

        #endregion

        #region 其他（初始化）
        private void Init()
        {
            //运行之后隐藏程序界面
            HideForm();
            //首次进行
            //获取程序占用空间
            R.AppSize = DirTool.GetPathSize(R.Paths.Root);
            //IP定位信息
            R.IPLocation = IPLocationTool.GetLocation();
            if (R.IPLocation != null) LBIPLocation.Text = $"IP定位：{R.IPLocation.SematicDescription}";
            else LBIPLocation.Text = "IP定位：暂无信息";
            LBMachine.Text = $"计算机名称：{R.MachineName}";
            LBPermission.Text = $"用户权限：{(R.IsAdministrator ? "管理员" : "普通用户")}";
            LBAppSize.Text = $"程序占用磁盘：{ByteConvertTool.Cvt(R.AppSize, "MB")} MB";
            //用户信息
            LBIPAddress.Text = $"IP：{R.NetInfo.IP}";
            LBMACAddress.Text = $"MAC：{NetCardInfoTool.MACFormat(R.NetInfo.Mac)}";
            LBGateway.Text = $"网关：{R.NetInfo.Gateway}";
        }
        #endregion

        #region 网络（初始化）

        /// <summary>
        /// 网络初始化
        /// </summary>
        private void NetWorkInit()
        {
            //新版本Socket通信
            R.Socket.Current = new SocketTool(R.Config.SOCKET_IP, R.Config.SOCKET_PORT);
            R.Socket.Current.ReadEvent += SocketReadEvent.Read;//绑定读取信息方法
            R.Socket.Current.StatusEvent += SocketStatusEvent.Update;//绑定更新状态方法
            SocketHeartbeat.Start();//启动心跳

            SocketSendQueue.Start();//启动发送信息队列
            WebApiSendQueue.Start();//启动Web信息发送队列
            Task.Factory.StartNew(() =>
            {
                while (!R.Socket.ConnectCancelToken.IsCancellationRequested)
                {
                    R.Socket.Current.Read();//开始通信，阻塞状态
                    Thread.Sleep(500);//读取增加间隔，有助于减少粘包
                }
            });
        }

        #endregion

        #region 退出程序

        /// <summary>
        /// 退出APP
        /// </summary>
        public void ExitApp()
        {
            SystemSleepAPI.ResotreSleep();//恢复计算机息屏和待机

            Task.Factory.StartNew(() =>
            {
                try
                {
                    R.Socket.Current.Close();
                    R.Socket.Current.ReadEvent -= SocketReadEvent.Read;
                    R.Socket.Current.StatusEvent -= SocketStatusEvent.Update;
                }
                catch { }

                Invoke(new Action(() =>
                {
                    Application.Exit();
                    Application.Exit();
                    Application.Exit();
                }));
            });
        }

        #endregion

        #region 右下角图标菜单
        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
            Application.Exit();
            Application.Exit();
        }

        private void 显示ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowForm();
        }

        private void NIMain_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            ShowForm();
        }

        #endregion

        #region 窗口的关闭和隐藏
        /// <summary>
        /// 隐藏窗口
        /// </summary>
        private void HideForm()
        {
            ShowInTaskbar = false;//使用ShowInTaskbar-false，将导致无法接受剪贴板事件
            WindowState = FormWindowState.Minimized;
        }
        /// <summary>
        /// 显示窗口
        /// </summary>
        private void ShowForm()
        {
            ShowInTaskbar = true;//使用ShowInTaskbar-false，将导致无法接受剪贴板事件
            if (WindowState == FormWindowState.Minimized) WindowState = FormWindowState.Normal;
            Activate();
        }
        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            HideForm();
            switch (e.CloseReason)
            {
                case CloseReason.None:
                    e.Cancel = true;
                    break;
                case CloseReason.WindowsShutDown:
                    break;
                case CloseReason.MdiFormClosing:
                    e.Cancel = true;
                    break;
                case CloseReason.UserClosing:
                    e.Cancel = true;
                    break;
                case CloseReason.TaskManagerClosing:
                    e.Cancel = true;
                    break;
                case CloseReason.FormOwnerClosing:
                    e.Cancel = true;
                    break;
                case CloseReason.ApplicationExitCall:
                    break;
            }
        }

        private void TabPageReflesh()
        {
            if (R.MainUI != null)
            {
                foreach (TabPage p in TCFunction.TabPages)
                {
                    p.Refresh();

                }
            }
           
        }

        #endregion

        #region 窗体布局
        /// <summary>
        /// 隐藏TabControl标签，调整显示区域
        /// </summary>
        private void HideTabControlHead()
        {
            TCFunction.SizeMode = TabSizeMode.Fixed;
            TCFunction.ItemSize = new Size(0, 1);

            switch (TCFunction.SelectedTab.Name)
            {
                case "TPMain":
                    TCFunction.Region = new Region(new RectangleF(TPMain.Left, TPMain.Top, TPMain.Width, TPMain.Height));
                    break;
                case "TPUserInfo":
                    TCFunction.Region = new Region(new RectangleF(TPUserInfo.Left, TPUserInfo.Top, TPUserInfo.Width, TPUserInfo.Height));
                    break;
            }
        }
        #endregion

        #region 时间控件UI刷新

        private void TMMain_Tick(object sender, EventArgs e)
        {
            try
            {
                //右下图标显示
                if (!NIMain.Visible) NIMain.Visible = true;

                //时间信息
                string date = DateTime.Now.ToString("yyyy年MM月dd日");
                string time = DateTime.Now.ToString("H:mm:ss");
                string desc = ChineseHourTool.GetDesc(DateTime.Now);
                LBRamInfo.Text = $"程序占用RAM：{ByteConvertTool.Fmt(R.AppRam)}"; ;
                LBTime.Text = $"{date} {desc} {time}";
                LB_USER_2.Text = R.UserName;
                LB_ACCOUNT_2.Text = R.Account;
            }
            catch { }
        }
        private void TMMain5_Tick(object sender, EventArgs e)
        {
            try
            {
                //用户信息
                LBIPAddress.Text = $"IP：{R.NetInfo.IP}";
                LBMACAddress.Text = $"MAC：{NetCardInfoTool.MACFormat(R.NetInfo.Mac)}";
                LBGateway.Text = $"网关：{R.NetInfo.Gateway}";

                //更新Icon文本描述
                UpdateIconText();
            }
            catch { }
        }
        private void TMMain10_Tick(object sender, EventArgs e)
        {
            try
            {
                //IP定位信息
                if (R.IPLocation != null) LBIPLocation.Text = $"IP定位：{R.IPLocation.SematicDescription}";
                else LBIPLocation.Text = "IP定位：暂无信息";
                LBMachine.Text = $"计算机名称：{R.MachineName}";
                LBPermission.Text = $"用户权限：{(R.IsAdministrator ? "管理员" : "普通用户")}";
                LBAppSize.Text = $"程序占用磁盘：{ByteConvertTool.Cvt(R.AppSize, "MB")} MB";
            }
            catch { }
        }

        /// <summary>
        /// 更新右下角图标显示文本
        /// </summary>
        public void UpdateIconText()
        {
            try
            {
                BeginInvoke(new Action(() =>
                {
                    try
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.AppendLine($"{(R.Socket.IsConnect ? "在线" : "离线")}");
                        sb.AppendLine($"IP : {R.NetInfo.IP}");

                        string txt = sb.Length < 60 ? sb.ToString() : sb.ToString().Substring(0, 60);
                        if (NIMain.Text != txt) NIMain.Text = txt;
                    }
                    catch (Exception ex) { }
                }));
            }
            catch { }
        }
        #endregion

        #region 主界面按钮菜单

        public void FunctionMenu_Click(object sender, string menu)
        {
            switch (menu)
            {
                case "UserInfo":
                    //个人信息
                    TCFunction.SelectTab("TPUserInfo");
                    break;
                case "FileEncrypt":
                    //文件加密
                    TCFunction.SelectTab("TPFileEncrypt");
                    break;
                case "CreatePwd":
                    //生成密码
                    TCFunction.SelectTab("TPCreatePwd");
                    break;
                case "ClipBoard":
                    //剪切板
                    TCFunction.SelectTab("TPClipBoard");
                    break;
                case "OtherFun":
                    //其他快捷功能
                    //R.Toast.Show("暂未开放", "暂未开放此功能");
                    TCFunction.SelectTab("TPOtherFun");
                    break;
                case "Update":
                    //检查更新
                    if (R.Socket.IsConnect)
                    {
                        //请求新版本
                        SocketSendQueue.Add(MessageType.请求新版本号, new string[] { R.Version.ToString() }, 60);
                        R.Flag.IsUserClickUpdate = true;
                        R.Toast.Show("检查更新", "已向服务器请求最新版本");
                    }
                    else
                    {
                        R.Toast.Show("检查更新", "当前与服务器断开连接，请先连接网络。", 'w');
                    }
                    break;
                case "LogInfo":
                    //日志记录
                    R.Toast.Show("日志记录", "暂未开放，敬请期待");
                    break;

                case "Setting":
                    //设置
                    TCFunction.SelectTab("TPSettings");
                    break;
            }
        }

        private void IBUserInfoBack_Click(object sender, EventArgs e)
        {
            TCFunction.SelectTab("TPMain");
        }

        private void IBSettingsBack_Click(object sender, EventArgs e)
        {
            TCFunction.SelectTab("TPMain");
        }

        private void IBCreatePwdBack_Click(object sender, EventArgs e)
        {
            TCFunction.SelectTab("TPMain");
        }

        private void BTNClipBoard_Click(object sender, EventArgs e)
        {
            TCFunction.SelectTab("TPMain");
        }

        private void IBFileEncrypts_Click(object sender, EventArgs e)
        {
            TCFunction.SelectTab("TPMain");
        }
        private void IBShortCutBack_Click(object sender, EventArgs e)
        {
            TCFunction.SelectTab("TPMain");
        }


        //TCFunction.SelectTab("TPMain");

        #endregion

        #region 显示二维码
        private void PBClientInfoQrcode_Click(object sender, EventArgs e)
        {
            R.FormMan.GetUnique<ClientInfoQrcodeForm>().Show();
            R.FormMan.GetUnique<ClientInfoQrcodeForm>().Activate();
        }

        #endregion

        #region 生成随机密码
        private void BTN_CreatePwd_Click(object sender, EventArgs e)
        {
            set16GUID();
        }

        private void BTN_CreatePwd_32_Click(object sender, EventArgs e)
        {
            set32GUID();
        }

        public void set16GUID()
        {
            TB_CreatePwd.Text = "";

            for (int indexCount = 1; indexCount < 10; indexCount++)
            {
                TB_CreatePwd.AppendText("PWD" + indexCount + " : " + MD5Encrypt16(Guid.NewGuid().ToString()) + "\r\n");
            }

        }

        public void set32GUID()
        {
            TB_CreatePwd_32.Text = "";

            for (int indexCount = 1; indexCount < 10; indexCount++)
            {
                TB_CreatePwd_32.AppendText("PWD" + indexCount + " : " + MD5Encrypt32(Guid.NewGuid().ToString()) + "\r\n");
            }

        }

        /// <summary>
        /// 16位MD5加密
        /// </summary>
        /// <param name="password"></param>
        /// <returns></returns>
        public static string MD5Encrypt16(string password)
        {
            var md5 = new MD5CryptoServiceProvider();
            string t2 = BitConverter.ToString(md5.ComputeHash(Encoding.Default.GetBytes(password)), 4, 8);
            t2 = t2.Replace("-", "");
            return t2;
        }

        /// <summary>
        /// 32位MD5加密
        /// </summary>
        /// <param name="password"></param>
        /// <returns></returns>
        public static string MD5Encrypt32(string password)
        {
            string cl = password;
            string pwd = "";
            MD5 md5 = MD5.Create(); //实例化一个md5对像
                                    // 加密后是一个字节类型的数组，这里要注意编码UTF8/Unicode等的选择　
            byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(cl));
            // 通过使用循环，将字节类型的数组转换为字符串，此字符串是常规字符格式化所得
            for (int i = 0; i < s.Length; i++)
            {
                // 将得到的字符串使用十六进制类型格式。格式后的字符是小写的字母，如果使用大写（X）则格式后的字符是大写字符 
                pwd = pwd + s[i].ToString("X");

            }
            return pwd;
        }

        #endregion

        #region 剪切板

        #region 菜单操作
        private void 选择缓存路径ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string cachePath = SelectPath();
            if (cachePath != null && cachePath != "")
            {
                cachePath = DirTool.Combine(cachePath, "Data");
                IniTool.Set(R.Files.Settings, "dataPath", "BigClipboard-dataPath", cachePath);
                R.Paths.MyDataPath = cachePath;
            }
        }
        private void 清空ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ClipboardDataMan.Clear();
        }
        private void 关于ToolStripMenuItem_Click(object sender, EventArgs e)
        {
           
        }

        private void 报告问题ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string message = string.Format("mailto:{0}?subject={1}", R.EmailAddress, "BigClipboard : 问题");
            Process.Start(message);//调用进程启动邮件
        }

        private void 提供建议ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string message = string.Format("mailto:{0}?subject={1}", R.EmailAddress, "BigClipboard : 建议");
            Process.Start(message);//调用进程启动邮件
        }

        private void 缓存ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //没有文件夹，创建文件夹
            if (Directory.Exists(R.Paths.MyDataPath))
            {
                System.Diagnostics.Process.Start(R.Paths.MyDataPath);
            }
            else
            {
                Directory.CreateDirectory(R.Paths.MyDataPath);
                if (File.Exists(R.Paths.MyDataPath))
                {
                    System.Diagnostics.Process.Start(R.Paths.MyDataPath);
                }
            }

        }
        #endregion

        #region 列表表格操作
        public void UI_DGV_Add(ClipboardData data)
        {
            try
            {
                Invoke(new Action(() =>
                {
                    DGVList.Rows.Insert(0, data.CreateTime, data.Text?.Trim(), data.Id);
                }));
            }
            catch { }
        }
        public void UI_DGV_Clear()
        {
            try
            {
                Invoke(new Action(() =>
                {
                    DGVList.Rows.Clear();
                }));
            }
            catch { }
        }

        public void UI_PBI_Clear()
        {
            try
            {
                Invoke(new Action(() =>
                {
                    PBImage.Image = null;
                    TBText.Text = "";
                    DGVData.Rows.Clear();
                }));
            }
            catch { }
        }

        private void DGVList_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            DGVList_Select(e.RowIndex);
        }
        private void DGVList_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Up)
            {
                int index = DGVList.CurrentRow.Index - 1;
                DGVList_Select(index);
            }

            if (e.KeyCode == Keys.Down)
            {
                int index = DGVList.CurrentRow.Index + 1;
                DGVList_Select(index);
            }

            DGVList.Focus();
        }

        private void DGVList_Select(int index)
        {
            if (index >= 0 && index < DGVList.RowCount)
            {
                string id = DGVList.Rows[index].Cells["COLId"].Value.ToString();
                ClipboardData data = ClipboardDataMan.Get(id);
                if (data != null)
                {
                    R.CurrentClipboardData = data;
                    TBText.Clear();
                    PBImage.Image = null;
                    DGVData.Rows.Clear();
                    DGVData.Columns.Clear();
                    //设置富文本
                    //if (data.RichText != null)
                    //{
                    //    try
                    //    {
                    //        using (Stream s = new MemoryStream())
                    //        {
                    //            s.Position = 0;
                    //            s.Write(data.RichText, 0, data.RichText.Length);
                    //            s.Position = 0;
                    //            RTBRich.LoadFile(s, RichTextBoxStreamType.RichText);
                    //        }
                    //    }
                    //    catch (Exception e) { }
                    //}
                    //设置纯文本
                    if (data.Text != null)
                    {
                        //TCData.SelectTab("TPText");
                        TBText.AppendText(data.Text);
                    }
                    //设置表格
                    if (data.Text != null)
                    {
                        string[] rows = data.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
                        foreach (var _r in rows)
                        {
                            string[] _d = _r.Split('\t');
                            if (ListTool.HasElements(_d))
                            {
                                if (DGVData.Columns.Count < _d.Length)
                                {
                                    for (int i = DGVData.Columns.Count; i < _d.Length; i++)
                                    {
                                        DGVData.Columns.Add($"DGVData_COL{i}", $"{i + 1}");
                                    }
                                }
                                DGVData.Rows.Add(_d);
                            }
                        }
                    }
                    //设置图片
                    if (data.Image != null)
                    {
                        //计算图片显示大小  图片大的按比例缩放，图片小的直接贴上去
                        int weight = PNImageContainer.Width - 20 <= 0 ? 400 : PNImageContainer.Width - 20;
                        int heigit = PNImageContainer.Height - 20 <= 0 ? 300 : PNImageContainer.Height - 20;
                        int img_weight = data.Image.Width;
                        int img_height = data.Image.Height;

                        if (img_weight > weight)
                        {
                            double view_ratio = (double)img_weight / (double)img_height;
                            double img_ratio = (double)weight / (double)heigit;

                            if (Math.Abs(img_ratio - view_ratio) > 0.2)
                            {
                                double weight_ratio = (double)img_weight / (double)weight;
                                double height_ratio = (double)img_height / (double)heigit;

                                if (weight_ratio > height_ratio)
                                {
                                    weight = (int)(img_weight / height_ratio);
                                }
                                else
                                {
                                    heigit = (int)(img_height / weight_ratio);
                                }
                            }
                            PBImage.Image = SizeImage(data.Image, weight, heigit);
                        }
                        else
                        {
                            PBImage.Image = data.Image;
                        }

                        //TCData.SelectTab("TPImage");

                        PBImage.Update();
                    }
                }
            }
        }

        #endregion

        #region 监控剪贴板变化
        #region Definitions
        //Constants for API Calls...
        private const int WM_DRAWCLIPBOARD = 0x308;
        private const int WM_CHANGECBCHAIN = 0x30D;

        //Handle for next clipboard viewer...
        private IntPtr mNextClipBoardViewerHWnd;

        //API declarations...
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        static public extern IntPtr SetClipboardViewer(IntPtr hWndNewViewer);
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        static public extern bool ChangeClipboardChain(IntPtr HWnd, IntPtr HWndNext);
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern int SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);
        #endregion
        #region Message Process
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
                case WM_DRAWCLIPBOARD:
                    {
                        SendMessage(mNextClipBoardViewerHWnd, m.Msg, m.WParam.ToInt32(), m.LParam.ToInt32());
                        ClipboardDataMan.ReadClipboard();
                        break;
                    }
                case WM_CHANGECBCHAIN:
                    {
                        //Another clipboard viewer has removed itself...
                        if (m.WParam == (IntPtr)mNextClipBoardViewerHWnd)
                        {
                            mNextClipBoardViewerHWnd = m.LParam;
                        }
                        else
                        {
                            SendMessage(mNextClipBoardViewerHWnd, m.Msg, m.WParam.ToInt32(), m.LParam.ToInt32());
                        }
                        break;
                    }
            }
            base.WndProc(ref m);
        }
        #endregion
        #endregion

        #region 窗口的关闭和隐藏
  
        ///// <summary>
        ///// 这种方法仍然不能用Close主窗口的方式来关闭应用程序， 还得使用Application.Exit。
        ///// </summary>
        ///// <param name="value"></param>
        //protected override void SetVisibleCore(bool value)
        //{
        //    base.SetVisibleCore(false);
        //}
        /// <summary>
        /// 配置剪切板句柄
        /// </summary>
        /// <param name="e"></param>
        protected override void OnHandleCreated(EventArgs e)
        {
            mNextClipBoardViewerHWnd = SetClipboardViewer(this.Handle);
            base.OnHandleCreated(e);
        }

        protected override void OnHandleDestroyed(EventArgs e)
        {
            ChangeClipboardChain(this.Handle, mNextClipBoardViewerHWnd);
            base.OnHandleDestroyed(e);
        }

        #endregion

        #region 图片算法

        /// <summary> 
        /// 按照指定大小缩放图片 
        /// </summary> 
        /// <param name="srcImage"></param> 
        /// <param name="iWidth"></param> 
        /// <param name="iHeight"></param> 
        /// <returns></returns> 
        public static Bitmap SizeImage(Image srcImage, int iWidth, int iHeight)
        {
            try
            {
                // 要保存到的图片 
                Bitmap b = new Bitmap(iWidth, iHeight);
                Graphics g = Graphics.FromImage(b);
                // 插值算法的质量 ， 这里图片质量用最低
                g.InterpolationMode = InterpolationMode.Low;
                g.DrawImage(srcImage, new Rectangle(0, 0, iWidth, iHeight), new Rectangle(0, 0, srcImage.Width, srcImage.Height), GraphicsUnit.Pixel);
                g.Dispose();
                return b;
            }
            catch (Exception)
            {
                return null;
            }
        }
        #endregion

        #region 窗体大小改变

        /// <summary>
        /// 窗体大小改变
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MainForm_Resize(object sender, EventArgs e)
        {
            //TabPageReflesh();
            //if (DGVList != null && DGVList.CurrentRow != null)
            //{
            //    int index = DGVList.CurrentRow.Index;
            //    DGVList_Select(index);
            //}
        }

        #endregion

        #region 配置缓存路径

        /// <summary>
        /// 选择文件夹路径
        /// </summary>
        /// <returns></returns>
        private string SelectPath()
        {
            string path = string.Empty;
            System.Windows.Forms.FolderBrowserDialog fbd = new System.Windows.Forms.FolderBrowserDialog();
            if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                path = fbd.SelectedPath;
            }
            return path;
        }

        #endregion

        #region 复制图片

        private void PBImage_MouseClick(object sender, MouseEventArgs e)
        {
            //弹出操作菜单
            PBIMenuStrip.Show(MousePosition.X, MousePosition.Y);
        }

        private void 复制此图片ToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            if (R.CurrentClipboardData != null && R.CurrentClipboardData.Image != null)
            {
                Clipboard.Clear();//清空剪切板内容
                Clipboard.SetImage(R.CurrentClipboardData.Image);
            }
        }



        #endregion

        #region 点击事件
        private void MCCBSettingColor_SelectedIndexChanged(object sender, EventArgs e)
        {
            var SelectedColor = MCCBSettingColor.SelectColor;
            IniTool.Set(R.Files.Settings, "Settings", "BackColor", ColorTranslator.ToHtml(SelectedColor));
            SingleTitleFormPNHead.BackColor = SelectedColor;
            panel1.BackColor = SelectedColor;
            //默认颜色 #2f4f4f

        }

        private void BTSearch_Click(object sender, EventArgs e)
        {
            ClipboardDataMan.Search(TBSearch.Text);
        }
        #endregion

        #endregion

    
    }
}
